package com.gs.SynAntiWandering.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.gs.SynAntiWandering.R;
import com.gs.SynAntiWandering.adapter.base.BaseAdapter;
import com.gs.SynAntiWandering.adapter.base.BaseViewHolder;
import com.gs.SynAntiWandering.constant.AllConstants;
import com.gs.SynAntiWandering.db.dto.InsightInOutDto;
import com.gs.SynAntiWandering.util.DateUtil;
import com.gs.SynAntiWandering.util.OKHttpUtil;
import com.gs.SynAntiWandering.util.SPUtil;

import java.util.List;


public class InsightInOutAdapter extends BaseAdapter<InsightInOutDto> {

    public InsightInOutAdapter(Context context, List<InsightInOutDto> mDatas, int layoutId) {
        super(context, mDatas, layoutId);
    }

    @Override
    public void convert(BaseViewHolder holder, InsightInOutDto item, final int position) {
        String photo;
        int photoType = SPUtil.getInstance().getInt(AllConstants.PHOTO_TYPE, 1);
        if (photoType == 1) {
            photo = item.getEnrollPhoto();
        } else {
            photo = TextUtils.isEmpty(item.getPhoto()) ? item.getEnrollPhoto() : item.getPhoto();
        }
        holder.setPersonImageResource(context, R.id.iv_photo, OKHttpUtil.IMG_URL + photo);
        holder.setText(R.id.tv_first, item.getDeviceName() == null ? "" : item.getDeviceName());
        holder.setText(R.id.tv_card_no, item.getCardNo() == null ? "" : item.getCardNo());
        if (item.getTime() != null) {
            holder.setText(R.id.tv_second, DateUtil.getInstance().DateTimeToStr(item.getTime()));
            holder.setText(R.id.tv_third, DateUtil.getInstance().DateTimeToStr(item.getTime(), "HH:mm:ss"));
        }
        holder.setText(R.id.tv_fourth, item.getMemberName() == null ? "" : item.getMemberName());
        String floor = item.getFloorName() == null ? "" : item.getFloorName();
        String room = item.getRoomNum() == null ? "" : item.getRoomNum();
        String bed = item.getBedNum() == null ? "" : item.getBedNum();
        holder.setText(R.id.tv_fifth, context.getString(R.string.room_info, floor, room, bed));
        holder.setText(R.id.tv_sixth, item.getTypeName() == null ? "" : item.getTypeName());
//        if (item.getIoType() != null) {
//            if (item.getIoType() == 1) {
//                holder.setVisibility(R.id.item_type_o, View.GONE);
//                holder.setVisibility(R.id.item_type_i, View.VISIBLE);
//            } else if (item.getIoType() == 2) {
//                holder.setVisibility(R.id.item_type_o, View.VISIBLE);
//                holder.setVisibility(R.id.item_type_i, View.GONE);
//            } else if (item.getIoType() == 3) {
//                holder.setVisibility(R.id.item_type_o, View.VISIBLE);
//                holder.setVisibility(R.id.item_type_i, View.VISIBLE);
//            }
//        }
    }
}
